package com.smartwebx.ha.web.util.kml;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;

import com.smartwebx.ha.util.KmlLine;
import com.smartwebx.ha.util.KmlPoint;
import com.smartwebx.ha.util.KmlProperty;


public class GetKml {
	@SuppressWarnings("unchecked")
	public KmlProperty readKml() throws IOException{
		File file= new File("D:"+File.separator+"等值线.txt");
		Reader input = new FileReader(file);
		char[] c = new char[(int)file.length()];
		int len =input.read(c);
		String str = new String(c,0,len);
		KmlProperty kmlProperty= new KmlProperty();
		List<KmlPoint> kmlpoints= new ArrayList<KmlPoint>();
		List<KmlLine> kmlLines= new ArrayList<KmlLine>();
		String[] s=str.split("\\|");
		StringBuffer kmlLineStr = new StringBuffer();
		
		int i,j=0;
		for(i=j; i<s.length; i++){
			KmlPoint kmlPoint = new KmlPoint();
			KmlLine kmlLine = new KmlLine();
			if(s[i].startsWith("9999")){
				String[] s2=s[i].split(",");
				kmlPoint.setPoints(s[i-1]);
				kmlPoint.setPointVal(s2[1]);
				kmlpoints.add(kmlPoint);
				kmlLineStr.delete(kmlLineStr.length()-1, kmlLineStr.length());
				kmlLine.setPoints(kmlLineStr.toString());
				kmlLines.add(kmlLine);
				kmlLineStr=new StringBuffer();
				kmlProperty.setKmlLines(kmlLines);
				kmlProperty.setKmlPoints(kmlpoints);
				j=i-1;
			}else{
				kmlLineStr.append(s[i]).append(";");
			}
		}
		return kmlProperty;
	}
}
